//package com.quartet.modules.equipment.controller;
//
//
//import cn.hutool.core.bean.BeanUtil;
//import com.alibaba.fastjson.JSON;
//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
//import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
//import com.baomidou.mybatisplus.core.metadata.IPage;
//import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
//import com.quartet.api.ApiResult;
//import com.quartet.api.PageResult;
//import com.quartet.modules.equipment.dto.TAlarmInfoAddRequestDto;
//import com.quartet.modules.equipment.dto.TAlarmInfoRequestDto;
//import com.quartet.modules.equipment.dto.TAlarmInfoResponseDto;
//import com.quartet.modules.equipment.entity.TAlarmProcessingInfo;
//import com.quartet.modules.equipment.service.TAlarmInfoService;
//import com.quartet.modules.service.aspect.AuthKeyValidated;
//import com.quartet.modules.vehicle.entity.TVehicleInfo;
//import com.quartet.modules.vehicle.service.TVehicleInfoService;
//import com.quartet.utils.JsonTool;
//import com.quartet.utils.constant.MapServerConstant;
//import io.swagger.annotations.Api;
//import io.swagger.annotations.ApiOperation;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.commons.lang.StringUtils;
//import org.apache.commons.lang3.ObjectUtils;
//import org.springframework.transaction.annotation.Transactional;
//import org.springframework.util.CollectionUtils;
//import org.springframework.web.bind.annotation.*;
//
//import javax.annotation.Resource;
//import java.util.ArrayList;
//import java.util.List;
//import java.util.stream.Collectors;
//
///**
// * 报警信息表(TAlarmInfo)表控制层
// *
// * @author makejava
// * @since 2021-05-04 12:10:03
// */
//@RestController
//@RequestMapping("tAlarmInfo")
//@Api(tags = "业务：报警信息")
//@Slf4j
//public class TAlarmInfoController  {
//    /**
//     * 服务对象
//     */
//    @Resource
//    private TAlarmInfoService tAlarmInfoService;
//    /**
//     * 服务对象
//     */
//    @Resource
//    private TVehicleInfoService tVehicleInfoService;
//    /**
//     * 服务对象
//     */
//    @Resource
//    private TOtherAlarmInfoService tOtherAlarmInfoService;
//
//    /**
//     * 分页查询所有数据
//     *
//     * @param tAlarmInfoRequestDto 查询实体
//     * @return 所有数据
//     */
//    @ApiOperation("分页查询所有报警信息")
//    @PostMapping("/select-page")
//    @AuthKeyValidated("alarm")
//    public ApiResult<PageResult<TAlarmInfoResponseDto>> selectAlarmPage(@RequestBody TAlarmInfoRequestDto tAlarmInfoRequestDto) {
//        log.info("---------selectCustomerPage begin, selectAlarmPage is {}----------", tAlarmInfoRequestDto);
//        IPage<TAlarmProcessingInfo> page = new Page<>(tAlarmInfoRequestDto.getCurrent(), tAlarmInfoRequestDto.getLimit());
//        QueryWrapper<TAlarmProcessingInfo> queryWrapper = new QueryWrapper<>();
//        if (!CollectionUtils.isEmpty(tAlarmInfoRequestDto.getCustomerCodeList())) {
//            queryWrapper.lambda().in(TAlarmProcessingInfo::getCustomerCode, tAlarmInfoRequestDto.getCustomerCodeList());
//        }
//        if (!CollectionUtils.isEmpty(tAlarmInfoRequestDto.getAlarmTypeList())) {
//            queryWrapper.lambda().in(TAlarmProcessingInfo::getAlarmType, tAlarmInfoRequestDto.getAlarmTypeList());
//        }
//        if (StringUtils.isNotBlank(tAlarmInfoRequestDto.getField())) {
//            queryWrapper.orderBy(true, tAlarmInfoRequestDto.isAsc(), tAlarmInfoRequestDto.getField());
//        } else {
//            queryWrapper.orderBy(true, tAlarmInfoRequestDto.isAsc(), MapServerConstant.CREATE_TIME);
//        }
//        IPage<TAlarmProcessingInfo> dbResult = tAlarmInfoService.page(page, queryWrapper);
//        PageResult<TAlarmInfoResponseDto> pageResult = new PageResult();
//        List<TAlarmInfoResponseDto> tAlarmInfoResponseDtoList = dbResult.getRecords().stream().map(tAlarmInfo -> {
//            TAlarmInfoResponseDto tAlarmInfoResponseDto = getAlarmInfoResponseDto(tAlarmInfo);
//            return tAlarmInfoResponseDto;
//        }).collect(Collectors.toList());
//        pageResult.setTotal(dbResult.getTotal());
//        pageResult.setData(tAlarmInfoResponseDtoList);
//        log.info("---------selectAlarmPage end, data is {}----------", pageResult);
//        return ApiResult.ok(pageResult);
//    }
//
//    /**
//     * 通过主键查询单条数据
//     *
//     * @param id 主键
//     * @return 单条数据
//     */
//    @ApiOperation("通过主键查询单条报警信息")
//    @GetMapping("/selectById")
//    @AuthKeyValidated("alarm")
//    public ApiResult<TAlarmInfoResponseDto> selectById(@RequestParam("id") String id) {
//        log.info("---------selectById begin, id is {}----------", id);
//        TAlarmProcessingInfo tAlarmProcessingInfo = tAlarmInfoService.getById(id);
//        TAlarmInfoResponseDto tAlarmInfoResponseDto = getAlarmInfoResponseDto(tAlarmProcessingInfo);
//        return ApiResult.ok(tAlarmInfoResponseDto);
//    }
//
//    /**
//     * 拷贝info到dto
//     *
//     * @param tAlarmProcessingInfo
//     * @return
//     */
//    private TAlarmInfoResponseDto getAlarmInfoResponseDto(TAlarmProcessingInfo tAlarmProcessingInfo) {
//        TAlarmInfoResponseDto tAlarmInfoResponseDto = BeanUtil.copyProperties(tAlarmProcessingInfo, TAlarmInfoResponseDto.class);
//        if (ObjectUtils.isNotEmpty(tAlarmProcessingInfo.getAlarmIssueCommand())) {
//            List<String> alarmIssueCommandList = JSON.parseArray(tAlarmProcessingInfo.getAlarmIssueCommand().toString(), String.class);
//            tAlarmInfoResponseDto.setAlarmIssueCommand(alarmIssueCommandList);
//        }
//        if (ObjectUtils.isNotEmpty(tAlarmProcessingInfo.getAlarmPromptSelection())) {
//            List<String> alarmPromptSelectionList = JSON.parseArray(tAlarmProcessingInfo.getAlarmPromptSelection().toString(), String.class);
//            tAlarmInfoResponseDto.setAlarmPromptSelection(alarmPromptSelectionList);
//        }
//        if (ObjectUtils.isNotEmpty(tAlarmProcessingInfo.getCaptureChannel())) {
//            List<String> captureChannelList = JSON.parseArray(tAlarmProcessingInfo.getCaptureChannel().toString(), String.class);
//            tAlarmInfoResponseDto.setCaptureChannel(captureChannelList);
//        }
//        if (ObjectUtils.isNotEmpty(tAlarmProcessingInfo.getEnterpriseSmsReceiver())) {
//            List<String> enterpriseSmsReceiverList = JSON.parseArray(tAlarmProcessingInfo.getEnterpriseSmsReceiver().toString(), String.class);
//            tAlarmInfoResponseDto.setEnterpriseSmsReceiver(enterpriseSmsReceiverList);
//        }
//        return tAlarmInfoResponseDto;
//    }
//
//    /**
//     * 新增数据
//     *
//     * @param tAlarmInfoRequestDto 实体对象
//     * @return 新增结果
//     */
//    @ApiOperation("增加报警信息")
//    @PostMapping("/add")
//    @Transactional(rollbackFor = Exception.class)
//    @AuthKeyValidated("alarm")
//    public ApiResult add(@RequestBody TAlarmInfoAddRequestDto tAlarmInfoRequestDto) {
//        log.info("---------add begin, tAlarmInfoRequestDto is {}----------", tAlarmInfoRequestDto);
//        List<TAlarmProcessingInfo> tAlarmProcessingInfoList = new ArrayList<>();
//        tAlarmInfoRequestDto.getAlarmTypeList().forEach(x -> tAlarmInfoRequestDto.getCustomerCodeList().forEach(y -> {
//            TAlarmProcessingInfo tAlarmProcessingInfo = copyAlarmDtoToInfo(tAlarmInfoRequestDto);
//            tAlarmProcessingInfo.setCustomerCode(y);
//            tAlarmProcessingInfo.setAlarmType(x);
//            tAlarmProcessingInfoList.add(tAlarmProcessingInfo);
//        }));
//        this.tAlarmInfoService.saveBatch(tAlarmProcessingInfoList);
//        //更新报警表的处理状态
//        QueryWrapper<TVehicleInfo> queryWrapper = new QueryWrapper();
//        queryWrapper.lambda().in(TVehicleInfo::getCustomerCode, tAlarmInfoRequestDto.getCustomerCodeList());
//        List<TVehicleInfo> tVehicleInfoList = tVehicleInfoService.list(queryWrapper);
//
//        List<String> vehicleCodeList = tVehicleInfoList.stream().map(tVehicleInfo -> tVehicleInfo.getVehicleCode()).collect(Collectors.toList());
//        UpdateWrapper<TOtherAlarmInfo> updateWrapper = new UpdateWrapper<>();
//        updateWrapper.lambda().in(TOtherAlarmInfo::getAlarmType, tAlarmInfoRequestDto.getAlarmTypeList())
//                .in(TOtherAlarmInfo::getVehicleCode, vehicleCodeList);
//        updateWrapper.lambda().set(TOtherAlarmInfo::getAlarmProcessMode, tAlarmInfoRequestDto.getAlarmProcessMode());
//        tOtherAlarmInfoService.update(updateWrapper);
//        return ApiResult.ok();
//    }
//
//    /**
//     * 复制告警信息DTO到INFO
//     *
//     * @param tAlarmInfoRequestDto
//     * @return
//     */
//    private TAlarmProcessingInfo copyAlarmDtoToInfo(@RequestBody TAlarmInfoAddRequestDto tAlarmInfoRequestDto) {
//        TAlarmProcessingInfo tAlarmProcessingInfo = BeanUtil.copyProperties(tAlarmInfoRequestDto, TAlarmProcessingInfo.class);
//        tAlarmProcessingInfo.setAlarmIssueCommand(JsonTool.beanToJson(tAlarmInfoRequestDto.getAlarmIssueCommand()));
//        tAlarmProcessingInfo.setAlarmPromptSelection(JsonTool.beanToJson(tAlarmInfoRequestDto.getAlarmPromptSelection()));
//        tAlarmProcessingInfo.setCaptureChannel(JsonTool.beanToJson(tAlarmInfoRequestDto.getCaptureChannel()));
//        tAlarmProcessingInfo.setEnterpriseSmsReceiver(JsonTool.beanToJson(tAlarmInfoRequestDto.getEnterpriseSmsReceiver()));
//        return tAlarmProcessingInfo;
//    }
//
//    /**
//     * 修改数据
//     *
//     * @param tAlarmInfoRequestDto 实体对象
//     * @return 修改结果
//     */
//    @ApiOperation("修改报警信息")
//    @PutMapping("/update")
//    @AuthKeyValidated("alarm")
//    public ApiResult updateAlarm(@RequestBody TAlarmInfoAddRequestDto tAlarmInfoRequestDto) {
//        log.info("---------updateAlarm begin, tAlarmInfoRequestDto is {}----------", tAlarmInfoRequestDto);
//        TAlarmProcessingInfo tAlarmProcessingInfo = copyAlarmDtoToInfo(tAlarmInfoRequestDto);
//        return ApiResult.ok(this.tAlarmInfoService.updateById(tAlarmProcessingInfo));
//    }
//
//    /**
//     * 删除数据
//     *
//     * @param id 主键结合
//     * @return 删除结果
//     */
//    @ApiOperation("删除报警信息")
//    @DeleteMapping("/delete")
//    @AuthKeyValidated("alarm")
//    public ApiResult deleteAlarm(@RequestParam("id") Integer id) {
//        log.info("---------deleteAlarm begin, id is {}----------", id);
//        return ApiResult.ok(this.tAlarmInfoService.removeById(id));
//    }
//
//    /**
//     * 启用停用
//     *
//     * @param id 主键
//     * @return 启用停用结果
//     */
//    @ApiOperation("启用停用")
//    @DeleteMapping("/changeStatus")
//    @AuthKeyValidated("alarm")
//    public ApiResult changeStatus(@RequestParam("id") Integer id, @RequestParam("status") Integer status) {
//        log.info("---------changeStatus begin, id and status is {},{}----------", id, status);
//        UpdateWrapper<TAlarmProcessingInfo> updateWrapper = new UpdateWrapper();
//        updateWrapper.lambda().eq(TAlarmProcessingInfo::getId, id).set(TAlarmProcessingInfo::getStatus, status);
//        return ApiResult.ok(tAlarmInfoService.update(updateWrapper));
//    }
//}
